package com.finchina.myview.ball;

import android.animation.TypeEvaluator;

/**
 * 作者：黄赛赛 on 2015/9/7 09:34
 *
 * @version V1.0
 * @Description: ${todo}()
 */
public class ColorEvaluate implements TypeEvaluator<MyColor> {
    @Override
    public MyColor evaluate(float fraction, MyColor startValue, MyColor endValue) {
        MyColor result = new MyColor();
        result.alpha = (int) (startValue.alpha + fraction * (endValue.alpha - startValue.alpha));
        result.red = (int) (startValue.red + fraction * (endValue.red - startValue.red));
        result.green = (int) (startValue.green + fraction * (endValue.green - startValue.green));
        result.blue = (int) (startValue.blue + fraction * (endValue.blue - startValue.blue));

        // 将计算出的当前颜色的值组装返回
//        String currentColor = "#" + getHexString(result.alpha)
//                + getHexString(result.red) + getHexString(result.green) + getHexString(result.blue);
        return result;
    }

    /**
     * 将10进制颜色值转换成16进制。
     */
    private String getHexString(int value) {
        String hexString = Integer.toHexString(value);
        if (hexString.length() == 1) {
            hexString = "0" + hexString;
        }
        return hexString;
    }
}
